package cjh.com.myiocannotation;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import cjh.com.myiocannotation.annotation.ContentView;
import cjh.com.myiocannotation.annotation.OnClick;
import cjh.com.myiocannotation.annotation.OnLongClick;
import cjh.com.myiocannotation.annotation.ViewInject;

//加载布局
@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {

    //加载控件id
    @ViewInject(R.id.btn_1)
    Button btn1;

    @ViewInject(R.id.btn_2)
    Button btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //初始化
        InjectUtils.inject(this);

        btn1.setText("曹俊豪1");
        btn2.setText("曹俊豪2");

    }


    @OnClick({R.id.btn_1,R.id.btn_2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_1:
                Toast.makeText(this, btn1.getText().toString()+"点击", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_2:
                Toast.makeText(this, btn2.getText().toString()+"点击", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    @OnLongClick({R.id.btn_1,R.id.btn_2})
    public boolean onLongClick(View view) {
        switch (view.getId()) {
            case R.id.btn_1:
                Toast.makeText(this, btn1.getText().toString()+"长按", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_2:
                Toast.makeText(this, btn2.getText().toString()+"长按", Toast.LENGTH_SHORT).show();
                break;
        }
        return true;
    }
}
